﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Odyssey.Linq;
using System.Configuration;
using SunTzu.Utility;

namespace Odyssey.Web.Models
{
    public static class EmailSender
    {
        static string smtpServer = ConfigurationManager.AppSettings["SmtpServer"];
        static string smtpUser = ConfigurationManager.AppSettings["SmtpUser"];
        static string smtpPassword = ConfigurationManager.AppSettings["SmtpPassword"];
        static string websiteRoot = ConfigurationManager.AppSettings["WebSiteRoot"];
        const string mailTitle = "文博会网站账户验证";
        const string mailContent0 = "<p>感谢您注册文博会网站</p><p>请点击此链接完成注册：<a href='{0}/account/validate?email={1}&vc={2}'>{0}/account/validate?email={1}&vc={2}</a></p>";
        const string mailContent1 = "<p>感谢您注册文博会网站</p><p>您的账号{0}已经验证完毕，可以正常使用了。</p>";

        public static void SendValidateEmail(tb_account account)
        {
            if (!account.IsValidate)
            {
                var content = string.Format(mailContent0, websiteRoot, account.Email, account.Password);
                if (SmtpMail.SendSMTPEMail(smtpServer, smtpUser, smtpPassword
                        , smtpUser, account.Email, mailTitle, content))
                {
                    // todo: log here
                }
            }
        }

        public static void SendValidateSuccess(tb_account account)
        {
            if (account.IsValidate)
            {
                var content = string.Format(mailContent1, account.Email);
                if (SmtpMail.SendSMTPEMail(smtpServer, smtpUser, smtpPassword
                        , smtpUser, account.Email, mailTitle, content))
                {
                    // todo: log here
                }
            }
        }
    }
}